

class JobResumeService:
    def __init__(self, session):
        self.session = session
    """
     个人查看投递以及被查看情况
    """

    def list_resume_watch_record(self, read=None, user_id=None):
        n_list = []
        b_sql = """select
        a.user_id,u.wx_nick_name user_name,u.wx_nick_name as resume_name,
        a.company_id,c.name company_name,a.job_id,j.job_name,a.read_count,
        a.deliver_date,a.resume_id,a.create_time
        FROM user_deliver_status a
				join user u on a.user_id=u.user_id
				join company c on a.company_id= c.company_id
		    join job j on a.job_id=j.job_id
        where a.user_id=:user_id and a.status=1""".strip()
        if read is not None:
            b_sql  = (b_sql + """ and a.read_count>0  """)
        result = self.session.execute(b_sql,{"user_id":user_id})
        if result:
            for d in result:
                n_list.append({
                    "company_id": d["company_id"] if d["company_id"] else '',
                    "company_name": d["company_name"] if d["company_name"] else '',
                    "user_id": d["user_id"] if d["user_id"] else '',
                    "user_name": d["user_name"] if d["user_name"] else '',
                    "job_id": d["job_id"] if d["job_id"] else '',
                    "job_name": d["job_name"] if d["job_name"] else '',
                    "deliver_date": d["deliver_date"].strftime('%Y-%m-%d %H:%M:%S') if d["deliver_date"] else '',
                    "resume_id": d["resume_id"] if d["resume_id"] else '',
                    "read_count": d["read_count"] if d["read_count"] else '0',
                    "resume_name": d["resume_name"] if d["resume_name"] else ''
                })
            return n_list
        else:
            return None


if __name__ == '__main__':
   pass
